# Author: Yang Yubo
# Email: yang@yangyubo.com

IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX )
    # SET(CMAKE_SHARED_LIBRARY_C_FLAGS "")            # -pic 
    # SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "")       # -shared
    # SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")         # +s, flag for exe link to use shared lib
    # SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "")       # -rpath
    # SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP "")   # : or empty

    # SET(CMAKE_LINK_LIBRARY_SUFFIX "")
    # SET(CMAKE_STATIC_LIBRARY_PREFIX "lib")
    # SET(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
	# especial for vxworks
	SET(CMAKE_SHARED_MODULE_PREFIX "")
	SET(CMAKE_SHARED_MODULE_SUFFIX ".o")
	
    SET(CMAKE_SHARED_LIBRARY_PREFIX "")          # lib
    SET(CMAKE_SHARED_LIBRARY_SUFFIX ".o")           # .a
	SET(CMAKE_LINK_LIBRARY_FLAG "")
    # SET(CMAKE_EXECUTABLE_SUFFIX "")             # same suffix as if built using UseEcos.cmake
    # SET(CMAKE_DL_LIBS "" )

    # SET(CMAKE_FIND_LIBRARY_PREFIXES "lib")
    # SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
	# SET(CMAKE_C_OUTPUT_EXTENSION ".o")
	# SET(CMAKE_CXX_OUTPUT_EXTENSION ".o")
	SET(CMAKE_C_CREATE_SHARED_MODULE "<CMAKE_LINKER> -o <TARGET> -r <OBJECTS> <LINK_LIBRARIES>")
	SET(CMAKE_CXX_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_MODULE})
	SET(CMAKE_C_CREATE_SHARED_LIBRARY "<CMAKE_LINKER> -o <TARGET> -r <OBJECTS> <LINK_LIBRARIES>")
	SET(CMAKE_CXX_CREATE_SHARED_LIBRARY ${CMAKE_C_CREATE_SHARED_LIBRARY})

    # Check $WIND_BASE env
    SET(WIND_BASE $ENV{WIND_BASE})
    IF(NOT WIND_BASE)
        MESSAGE(FATAL_ERROR "You MUST set $WIND_BASE environment.")
    ENDIF()

    # Check $WIND_PLATFORM env
    SET(WIND_PLATFORM $ENV{WIND_PLATFORM})
    IF(NOT WIND_PLATFORM)
        MESSAGE(FATAL_ERROR "You MUST set $WIND_PLATFORM environment.")
    ENDIF()

    # Set $WIND_HOST_TYPE env
    IF(CMAKE_HOST_WIN32)
        SET(ENV{WIND_HOST_TYPE} "x86-win32")
    ENDIF()
    
    SET(VXWORKS TRUE)
    
    # FOR vxworks 6.3
    IF(WIND_PLATFORM STREQUAL "vxworks-6.3")
        SET(VXWORKS_6X TRUE)
    ENDIF()

    # FOR vxworks 5.5
    IF (WIND_PLATFORM STREQUAL "vxworks-5.5")
        SET(VXWORKS_5X TRUE)
        IF(CMAKE_HOST_WIN32) # set PATH
            SET(ENV{PATH} "${WIND_BASE}\\host\\$ENV{WIND_HOST_TYPE}\\bin;$ENV{PATH}")
        ENDIF()
    ENDIF()
    
    # search for additional tools required for C/C++
    FIND_PROGRAM(VXWORKS_AR_PATH ${VXWORKS_AR})
    FIND_PROGRAM(VXWORKS_RANLIB_PATH ${VXWORKS_RANLIB})
    FIND_PROGRAM(VXWORKS_STRIP_PATH ${VXWORKS_STRIP})
    FIND_PROGRAM(VXWORKS_LINKER_PATH ${VXWORKS_LINKER})
    FIND_PROGRAM(VXWORKS_NM_PATH ${VXWORKS_NM})
    FIND_PROGRAM(VXWORKS_OBJDUMP_PATH ${VXWORKS_OBJDUMP})
    FIND_PROGRAM(VXWORKS_OBJCOPY_PATH ${VXWORKS_OBJCOPY})
    
    SET(CMAKE_AR ${VXWORKS_AR_PATH})
    SET(CMAKE_RANLIB ${VXWORKS_RANLIB_PATH})
    SET(CMAKE_STRIP ${VXWORKS_STRIP_PATH})
    SET(CMAKE_LINKER ${VXWORKS_LINKER_PATH})
    SET(CMAKE_NM ${VXWORKS_NM_PATH})
    SET(CMAKE_OBJDUMP ${VXWORKS_OBJDUMP_PATH})
    SET(CMAKE_OBJCOPY ${VXWORKS_OBJCOPY_PATH})
ENDIF()
